#ifndef MACH_O_LOADER_H
#define MACH_O_LOADER_H
typedef uint32_t cpu_type_t;
typedef uint32_t cpu_subtype_t;

struct mach_header
{
uint32_t magic;
cpu_type_t cputype;
cpu_subtype_t cpusubtype;
uint32_t filetype;
uint32_t ncmds;
uint32_t sizeofcmds;
uint32_t flags;
};

struct load_command
{
uint32_t cmd;
uint32_t cmdsize;
};

union lc_str
   {
      uint32_t offset;
      #ifndef __LP64__
      char *ptr;
      #endif
};

struct dylib
{
union lc_str  name;
   uint32_t timestamp;
   uint32_t current_version;
   uint32_t compatibility_version;
};

struct dylib_command
{
uint32_t cmd;
uint32_t cmdsize;
struct dylib dylib;
};

typedef uint32_t vm_prot_t;

struct segment_command
{
uint32_t cmd;
uint32_t cmdsize;
char segname[16];
uint32_t vmaddr;
uint32_t vmsize;
uint32_t fileoff;
uint32_t filesize;
vm_prot_t maxprot;
vm_prot_t initprot;
uint32_t nsects;
uint32_t flags;
};

struct section
{
char sectname[16];
char segname[16];
uint32_t addr;
uint32_t size;
uint32_t offset;
uint32_t align;
uint32_t reloff;
uint32_t nreloc;
uint32_t flags;
uint32_t reserved1;
uint32_t reserved2;
};

struct symtab_command
{
uint32_t cmd;
uint32_t cmdsize;
uint32_t symoff;
uint32_t nsyms;
uint32_t stroff;
uint32_t strsize;
};

struct dysymtab_command
{
uint32_t cmd;
uint32_t cmdsize;
uint32_t ilocalsym;
uint32_t nlocalsym;
uint32_t iextdefsym;
uint32_t nextdefsym;
uint32_t iundefsym;
uint32_t nundefsym;
uint32_t tocoff;
uint32_t ntoc;
uint32_t modtaboff;
uint32_t nmodtab;
uint32_t extrefsymoff;
uint32_t nextrefsyms;
uint32_t indirectsymoff;
uint32_t nindirectsyms;
uint32_t extreloff;
uint32_t nextrel;
uint32_t locreloff;
uint32_t nlocrel;
};

#define MH_MAGIC 0xfeedface
#define MH_CIGAM 0xcefaedfe
#define	MH_EXECUTE 2
#define MH_DYLIB 6
#define MH_BUNDLE 8
#define MH_OBJECT 1

#define FAT_MAGIC 0xcafebabe
#define FAT_CIGAM 0xbebafeca

#define CPU_TYPE_I386 7
#define LC_SEGMENT 1
#define LC_SYMTAB 2
#define LC_LOAD_DYLIB 0x0c
#define LC_UNIXTHREAD 0x05
#define LC_DYSYMTAB     0xb

#define N_EXT 1
#define REFERENCE_FLAG_UNDEFINED_LAZY 0x1
#define REFERENCE_FLAG_UNDEFINED_NON_LAZY 0x0
#define REFERENCE_TYPE 0xF
#endif
